//
//  ZWHomeVC.m
//  WanEr
//
//  Created by 高文萍 on 15/12/16.
//  Copyright © 2015年 高文萍. All rights reserved.
//

#import "ZWHomeVC.h"
#import "WanErHeader.h"
#import "ZWHomeModel.h"
#import "ZWHomeTableViewCell.h"
#import "ZWChouTiView.h"
#import "ZWPlayerVC.h"
#import "ZWSeachVC.h"
#import "ZWHomeDetail.h"
#import "ZWTextLabel.h"
#import "ZWHeaderView.h"
#import "ZWLikeVC.h"
#import "ZWLeaveDownVC.h"
#import "ZWLunBoView.h"
#import "ZWLuoBoModel.h"
#import "JXRDataCachesTool.h"
@interface ZWHomeVC ()<UITableViewDataSource,UITableViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
    UIImageView *_peopleImg;
}

@property (nonatomic, strong) UITableView *homeTableView;
@property (nonatomic, strong) UIImageView *headerImageView;
@property (nonatomic, strong) NSMutableDictionary *homeTableDic;
@property (nonatomic, strong) NSMutableArray *homeArr;
@property (nonatomic, strong) NSMutableArray *headerArr;
@property (nonatomic, strong) ZWBaseButton *seachButton;
@property (nonatomic, strong) ZWBaseButton *chouTiButton;
@property (nonatomic, strong) ZWChouTiView *chou_Ti_View;
@property (nonatomic, strong) UIView *choutibackView;
@property (nonatomic, strong) UIView *cityLabelView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) ZWHeaderView *headerText_View;
// 查看更多所需
@property (nonatomic, strong) UIImageView *moreImage;
@property (nonatomic, strong) UIView *moreBackView;
@property (nonatomic, strong) UILabel *moretextLabel;
@property (nonatomic, strong) UILabel *moretitleLabel;
@property (nonatomic, strong) UIButton *popButton;
@property (nonatomic, strong) UIView *backWindowView;
@property (nonatomic, strong) UIView *lineView;

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) ZWLunBoView *lun_boView;
@property (nonatomic, strong)NSMutableAttributedString *headerTextAtt;
@property (nonatomic, strong) MBProgressHUD *homeHud;

@end


@implementation ZWHomeVC


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.moretextLabel removeFromSuperview];
    [self.lun_boView addTimer];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.lun_boView removeTimer];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.homeTableDic = [NSMutableDictionary dictionary];
//    self.headerArr = [NSMutableArray array];

    // 刷新
    self.homeTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self createTableData];
        
    }];
    
    [self homeView];
    
    [self createButton];
    [self createChouTiView];
    

    
    [self createHeaderView];
    [self createMoreView];
    
    
    [self createTableData];
}

- (void)tapVClick:(UIPanGestureRecognizer *)tap
{
    
    UIPanGestureRecognizer *gesture = (UIPanGestureRecognizer *)tap;
    CGPoint point = [gesture translationInView:self.chou_Ti_View];
    CGPoint tablePoint = [gesture translationInView:self.homeTableView];
    NSLog(@"%f --- %f   --- %f",point.x,point.y,self.chou_Ti_View.frame.origin.x);
    if (self.chou_Ti_View.frame.origin.x + point.x< WIDTH / 4) {
        
        return ;
        
    }else{
        
        self.chou_Ti_View.transform = CGAffineTransformTranslate(self.chou_Ti_View.transform, point.x, self.chou_Ti_View.frame.origin.y);
        
        if (tap.state == UIGestureRecognizerStateRecognized) {
            NSLog(@"结束");
            
//            self.homeTableView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
            if (self.chou_Ti_View.frame.origin.x + point.x > 220) {
                
                [self setViewHidden:YES view:self.chou_Ti_View];
               
            }else{
                
                [self setViewHidden:NO view:self.chou_Ti_View];
            }
            
        }
        
    }
    
    
    [tap setTranslation:CGPointZero inView:self.chou_Ti_View];

}

#pragma mark 抽屉弹出消失时调用的方法
- (void)setViewHidden:(BOOL)hidden view:(UIView *)view{
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.15];
    if (hidden) {
        [view setFrame:CGRectMake(WIDTH, 0, WIDTH / 4 * 3 , HEIGHT)];
        
        // firstView 消失时 透明度变为零
        if (view == self.chou_Ti_View){
            self.choutibackView.alpha = 0;
        }
    }else{
        
        [view setFrame:CGRectMake(WIDTH / 4, 0,WIDTH / 4 * 3, HEIGHT)];
        self.choutibackView.alpha = 0.5;
    }
    [UIView commitAnimations];
}


#pragma ---自定义label----
- (void)resetHeaderContent
{
    if (self.headerText_View.mytextLabel.text) {
        
        self.headerText_View.mytextLabel.adjustsFontSizeToFitWidth = YES;
        self.headerText_View.mytextLabel.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:16];
        self.headerText_View.mytextLabel.textColor = [UIColor colorWithWhite:0.370 alpha:1.000];
        self.headerText_View.mytextLabel.numberOfLines = 7;
        
        self.headerTextAtt = [[NSMutableAttributedString alloc]initWithString:self.headerText_View.mytextLabel.text];
        // 首字体大小颜色位置
        [self.headerTextAtt addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithWhite:0.370 alpha:1.000] range:NSMakeRange(0,2)];
        [self.headerTextAtt addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:20.0] range:NSMakeRange(0, 2)];

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.alignment = NSTextAlignmentLeft;
        paragraphStyle.maximumLineHeight = 12;  //最大的行高
        paragraphStyle.lineSpacing = 12;  //行自定义行高度
        [paragraphStyle setFirstLineHeadIndent:20];//首行缩进 根据用户昵称宽度在加5个像素
        
        [self.headerTextAtt addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.headerText_View.mytextLabel.text.length)];
        self.headerText_View.mytextLabel.attributedText = self.headerTextAtt;
        [self.headerText_View.mytextLabel sizeToFit];
    }else{
        
        self.headerText_View.mytextLabel.text = @"数据出错";
    }
    
}

#pragma ---自定义moreLabel---
- (void)moreLabelContent
{
    if (self.moretextLabel.text) {
        
        self.moretextLabel.adjustsFontSizeToFitWidth = YES;
        self.moretextLabel.adjustsLetterSpacingToFitWidth = YES;
        self.moretextLabel.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:14];
        self.moretextLabel.textColor = [UIColor whiteColor];
        self.moretextLabel.numberOfLines = 40;
        
        self.headerTextAtt = [[NSMutableAttributedString alloc]initWithString:self.moretextLabel.text];
        // 首字体大小颜色位置
        [self.headerTextAtt addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,2)];
        [self.headerTextAtt addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:20.0] range:NSMakeRange(0, 2)];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.alignment = NSTextAlignmentLeft;
        paragraphStyle.maximumLineHeight = 60;  //最大的行高
        paragraphStyle.lineSpacing = 5;  //行自定义行高度
        [paragraphStyle setFirstLineHeadIndent:20];//首行缩进 根据用户昵称宽度在加5个像素
        
        [self.headerTextAtt addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.moretextLabel.text.length)];
        self.moretextLabel.attributedText = self.headerTextAtt;
        [self.moretextLabel sizeToFit];
    }else{
        
        self.moretextLabel.text = @"nil";
    }

    
}

#pragma --------tableView数据请求-----------
- (void)createTableData
{
    self.homeHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.homeHud.labelText = @"玩仔加速中...";
    self.homeHud.alpha = 0.5;
    self.homeHud.labelFont = [UIFont systemFontOfSize:14];
    self.homeHud.labelColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000];
    
//    NSString *str = @"http://app.ziwoxz.com/agi/index";
//    NSDictionary * userInfo = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil];
    
    
   [JXRAFNetWorkTool getNetWithURL:[[NSString stringWithFormat:@"http://app.ziwoxz.com/agi/index" ] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] body:nil resultKind:JXRJSON headerFile:nil success:^(id result) {
       
       
       self.homeArr = [ZWHomeModel baseModelByArr:result[@"data"][@"sceneries"] arr:self.homeArr];
       
       self.homeTableDic = result[@"data"][@"main_sceneries"];
       self.headerText_View.cityLabel.text = self.homeTableDic[@"scenerie_name"];
       self.headerText_View.mytextLabel.text = self.homeTableDic[@"comment"];
       self.headerText_View.chinaLabel.text = self.homeTableDic[@"country"];
       [self resetHeaderContent];
       
       self.moretextLabel.text = self.homeTableDic[@"comment"];
       [self moreLabelContent];
       
       NSMutableArray *arr = result[@"data"][@"main_sceneries"][@"image_url"];
       
       NSLog(@"arrr--%@", arr);
       self.headerArr = arr;
       NSLog(@"self.header---%@", self.headerArr);
       
       NSMutableArray *lunboArr = [NSMutableArray array];
       //        lunboArr = self.headerArr;
       for (NSString *str in self.headerArr) {
           [lunboArr addObject:str];
           
       }
       
       if (lunboArr.count) {
           NSString *lastStr = [lunboArr lastObject];
           NSString *firstStr = lunboArr[0];
           [lunboArr addObject:firstStr];
           [lunboArr insertObject:lastStr atIndex:0];
           self.lun_boView.scrollArr = lunboArr;
       }
       
       [self.homeTableView.header endRefreshing];
       [self.homeHud setHidden:YES];
       [self.homeHud removeFromSuperview];
       [self.homeTableView reloadData];
       
   } failure:^(NSError *error) {
       
//       self.homeHud.hidden = YES;
       
       

       
       if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
           
           UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"网络不稳定" message:@"请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
           //添加两个按钮
           UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
               
           }];
           [alert addAction:sureAction];
           [self presentViewController:alert animated:YES completion:nil];
           
       }else{
           
           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络不稳定" message:@"请连接网络后重试!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
           
           [alert show];
       }
       NSLog(@"%@",error);

    
   }];

    
}


#pragma ---头试图----
- (void)createHeaderView
{
    
    self.headerText_View.cityLabel.textColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000];
    self.headerText_View.cityLabel.font = [UIFont systemFontOfSize:26];
    

}

#pragma ---查看更多View----
- (void)createMoreView
{
    self.moreBackView = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT)];
    [self.view addSubview:self.moreBackView];
    
    self.moreImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.moreImage.image = [UIImage imageNamed:@"配图"];
    [self.moreBackView addSubview:self.moreImage];
    
    
    self.window = [[UIApplication sharedApplication].delegate window];
    self.backWindowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.backWindowView.backgroundColor = [UIColor darkGrayColor];
    self.backWindowView.alpha = 0;
    [self.window addSubview:self.backWindowView];
    
    
    
    self.moretitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 60 + HEIGHT, WIDTH, 30)];
    self.moretitleLabel.text = @"概况";
    self.moretitleLabel.textColor = [UIColor whiteColor];
    self.moretitleLabel.font = [UIFont systemFontOfSize:16 weight:1];
    self.moretitleLabel.textAlignment = NSTextAlignmentCenter;
    [self.window addSubview:self.moretitleLabel];
    
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(20, 70 + HEIGHT, WIDTH - 40, 2)];
    self.lineView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.lineView];
    
    // 文字适应label 更多
    // 更多字体
    self.moretextLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 70, WIDTH - 30, HEIGHT - 70 - 50)];
    [self.window addSubview:self.moretextLabel];
    
     self.popButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.popButton setImage:[UIImage imageNamed:@"Line + Line"] forState:UIControlStateNormal];
    [self.popButton addTarget:self action:@selector(popClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:self.popButton];

    
}


#pragma ---文字返回---
- (void)popClick:(UIButton *)button
{
    [UIView animateWithDuration:0.09 animations:^{
       
        self.moreBackView.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT);
        self.moretitleLabel.frame = CGRectMake(0, 60 + HEIGHT, WIDTH, 30);
        self.lineView.frame = CGRectMake(20, 100 + HEIGHT, WIDTH - 40, 2);
        self.popButton.frame = CGRectMake(WIDTH / 2 - 20, HEIGHT - 60 + HEIGHT, 40, 40);
        // 文字适应label
        self.moretextLabel.frame = CGRectMake(20 ,102 + HEIGHT, WIDTH - 40, HEIGHT - 100 - 70);
        self.backWindowView.alpha = 0;
        

        
    }];
    
}

#pragma --定义成方法方便多个label调用 增加代码的复用性--
- (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font
{
    
    CGRect rect = [string boundingRectWithSize:CGSizeMake(WIDTH - 40, 800) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil];
    return rect.size;
}

#pragma -----------试图创建----------
- (void)homeView
{
    self.homeTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    self.homeTableView.rowHeight = 275;
    self.homeTableView.dataSource = self;
    self.homeTableView.delegate = self;
    [self.view addSubview:self.homeTableView];
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, WIDTH * 2)];
    self.homeTableView.tableHeaderView = self.headerView;
    
    // (headerView)轮播图
    self.lun_boView = [[ZWLunBoView alloc]init];
    self.lun_boView.frame = CGRectMake(0, 0, WIDTH, WIDTH);
    [self.headerView addSubview:self.lun_boView];
    
    // (headerview)xib
    self.headerText_View = (ZWHeaderView *)[[[NSBundle mainBundle]loadNibNamed:@"header" owner:self options:nil] lastObject];
    self.headerText_View.frame = CGRectMake(0, WIDTH, WIDTH, WIDTH);
    
    self.headerText_View.chinaLabel.font = [UIFont systemFontOfSize:18];
    self.headerText_View.chinaLabel.textColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000];
    
    [self.headerText_View.moreButton setTitle:@"查看更多" forState:UIControlStateNormal];
    [self.headerText_View.moreButton setTitleColor:[UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000] forState:UIControlStateNormal];
    self.headerText_View.moreButton.titleLabel.font = [UIFont systemFontOfSize:14];
    self.headerText_View.moreButton.layer.borderWidth = 1;
    self.headerText_View.moreButton.layer.cornerRadius = 7;
    self.headerText_View.moreButton.layer.borderColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000].CGColor;
    self.headerText_View.moreButton.layer.masksToBounds = YES;
    [self.headerText_View.moreButton addTarget:self action:@selector(moreTextClick:) forControlEvents:UIControlEventTouchUpInside];
    self.headerText_View.lineOne.backgroundColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000];
    self.headerText_View.lineTwo.backgroundColor = [UIColor colorWithRed:0.554 green:0.406 blue:0.160 alpha:1.000];
    self.headerText_View.jingdianLabel.text = @"景点";
    self.headerText_View.jingdianLabel.textColor = [UIColor colorWithWhite:0.370 alpha:1.000];
    self.headerText_View.jingdianLabel.font = [UIFont systemFontOfSize:20];
    
    [self.headerView addSubview:self.headerText_View];
    


    
}
#pragma ----查看更多-----
- (void)moreTextClick:(UIButton *)button
{
    NSLog(@"查看更多");
    
    [UIView animateWithDuration:0.09 animations:^{
       
        [self.window addSubview:self.moretextLabel];
        self.moreBackView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
        self.backWindowView.alpha = 0.7;
        self.moretitleLabel.frame = CGRectMake(0, 60, WIDTH, 30);
        self.lineView.frame = CGRectMake(20, 100, WIDTH - 40, 2);
        self.popButton.frame = CGRectMake(WIDTH / 2 - 20, HEIGHT - 60, 40, 40);
        // 文字适应label
        self.moretextLabel.frame = CGRectMake(20 ,100 + 2 , WIDTH - 40,HEIGHT - 100 - 70);
        
    }];

}

#pragma -----------创建seach 抽屉------------
- (void)createButton
{
    
    self.seachButton = [ZWBaseButton baseButtonFrame:CGRectMake(25, 58, 40, 40) buttonType:UIButtonTypeCustom buttonTitle:nil buttonTitleColor:[UIColor whiteColor] buttonTag:100 buttonImage:[UIImage imageNamed:@"iconfont-sou"]];
    [self.seachButton addTarget:self action:@selector(seachClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.seachButton setBackgroundColor:[UIColor whiteColor]];
    self.seachButton.layer.borderWidth = 1;
    self.seachButton.layer.cornerRadius = 20;
    self.seachButton.layer.borderColor = [UIColor whiteColor].CGColor;
    self.seachButton.layer.masksToBounds = YES;
    [self.view addSubview:self.seachButton];
    
    self.chouTiButton = [ZWBaseButton baseButtonFrame:CGRectMake(WIDTH - 60, 58, 40, 35) buttonType:UIButtonTypeCustom buttonTitle:nil buttonTitleColor:nil buttonTag:101 buttonImage:[UIImage imageNamed:@"功能"]];
    [self.chouTiButton addTarget:self action:@selector(choutiClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.chouTiButton];
}
#pragma ------搜索点击------
- (void)seachClick:(ZWBaseButton *)button
{
    NSLog(@"搜索");
    ZWSeachVC *seachVc = [[ZWSeachVC alloc]init];
    [self.navigationController pushViewController:seachVc animated:YES];
    
    
}
#pragma --------抽屉点击-------
- (void)choutiClick:(ZWBaseButton *)button
{
    NSLog(@"抽屉");
    [self createChouTiView];
    [UIView animateWithDuration:0.5 animations:^{
        
        self.chou_Ti_View.frame = CGRectMake(WIDTH / 4, 0, WIDTH / 4 * 3, HEIGHT);
//        self.homeTableView.frame = CGRectMake(-WIDTH / 4 * 3, 0, WIDTH, HEIGHT);
        self.choutibackView.alpha = 0.5;
        
    }];
}
#pragma --------抽屉View创建------
- (void)createChouTiView
{
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    self.choutibackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.choutibackView.backgroundColor = [UIColor darkGrayColor];
    self.choutibackView.alpha = 0;
    [window addSubview:self.choutibackView];
    // 手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    [self.choutibackView addGestureRecognizer:tap];
    
    self.chou_Ti_View = (ZWChouTiView *)[[[NSBundle mainBundle]loadNibNamed:@"ChouTi" owner:self options:nil]lastObject];
    self.chou_Ti_View.frame = CGRectMake(WIDTH , 0, WIDTH / 4 * 3, HEIGHT);
    self.chou_Ti_View.backgroundColor = [UIColor whiteColor];

    _peopleImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 90, 90)];
    _peopleImg.layer.cornerRadius = 45;
    _peopleImg.layer.borderWidth = 1;
    _peopleImg.layer.borderColor = [UIColor whiteColor].CGColor;
    _peopleImg.layer.masksToBounds = YES;
    _peopleImg.backgroundColor = [UIColor clearColor];
//    [self.chou_Ti_View.myPhotoView addSubview:_peopleImg];
    [self.view addSubview:_peopleImg];
    [window addSubview:self.chou_Ti_View];
    
    // 滑动手势
    UIPanGestureRecognizer *tapV = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(tapVClick:)];
    [self.chou_Ti_View addGestureRecognizer:tapV];
    
    // 抽屉View按钮设置
//    self.chou_Ti_View.imageButon.layer.borderWidth = 1;
//    self.chou_Ti_View.imageButon.layer.cornerRadius = 45;
//    self.chou_Ti_View.imageButon.layer.borderColor = [UIColor whiteColor].CGColor;
//    self.chou_Ti_View.layer.masksToBounds = YES;
    [self.chou_Ti_View.changImgButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.changImgButton.tag = 1000;
    
    [self.chou_Ti_View.playerButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.playerButton.tag = 1001;
    
    [self.chou_Ti_View.likeButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.likeButton.tag = 1002;
    

    [self.chou_Ti_View.linedownButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.linedownButton.tag = 1003;
    
    [self.chou_Ti_View.leaveButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.leaveButton.tag = 1004;
    
    [self.chou_Ti_View.clearButton addTarget:self action:@selector(Chou_Ti_Click:) forControlEvents:UIControlEventTouchUpInside];
    self.chou_Ti_View.clearButton.tag = 1005;

}
#pragma -------抽屉上点击方法---------
- (void)Chou_Ti_Click:(UIButton *)button
{
    if (button.tag == 1000) {
        NSLog(@"更换头像");
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"更换头像" message:@"请选择" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"打开相册",@"打开相机", nil];
        alert.delegate = self;
        [alert show];
        
        
    }else if (button.tag == 1001){
        NSLog(@"正在播放");
        ZWPlayerVC *playerVC = [[ZWPlayerVC alloc]init];
        [UIView animateWithDuration:0.3 animations:^{
            
            self.chou_Ti_View.frame = CGRectMake(WIDTH, 0, WIDTH / 4 * 3, HEIGHT);
            self.choutibackView.alpha = 0;
            self.homeTableView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
            
        }];
        [self.navigationController pushViewController:playerVC animated:NO];
        
        
    }else if (button.tag == 1002){
        NSLog(@"喜欢");
        ZWLikeVC *likeVC = [[ZWLikeVC alloc]init];
        [self.navigationController pushViewController:likeVC animated:NO];
        [UIView animateWithDuration:0.3 animations:^{
            
            self.chou_Ti_View.frame = CGRectMake(WIDTH, 0, WIDTH / 4 * 3, HEIGHT);
            self.choutibackView.alpha = 0;
            self.homeTableView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
            
        }];
        
        
    }else if (button.tag == 1003){
        NSLog(@"离线");
        ZWLeaveDownVC *leaveDown = [[ZWLeaveDownVC alloc]init];
        leaveDown.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [self presentViewController:leaveDown animated:YES completion:nil];
        [UIView animateWithDuration:0.3 animations:^{
            
            self.chou_Ti_View.frame = CGRectMake(WIDTH, 0, WIDTH / 4 * 3, HEIGHT);
            self.choutibackView.alpha = 0;
            self.homeTableView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
            
        }];

        
    }else if (button.tag == 1004){
        NSLog(@"退出登录");
        
    }else if (button.tag == 1005){
        NSLog(@"清除缓存");
        //清理内存
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"友情提示:" message:@"是否清理缓存" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[JXRDataCachesTool shareJXRDataCachesTool]clearCache];
//            [[JXRDataManagerTool shareJXRDataManagerTool]deleteAllSongs];
            
        }];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        [alert addAction:okAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        

    }
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) return NSLog(@"取消");
    if (buttonIndex == 1){
        
        NSLog(@"打开相册");
        //相册是可以用模拟器打开的
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            // 是否可以进行编辑
            picker.allowsEditing = YES;
            
            // 打开相册选择照片
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:^{
                
                
            }];
            
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"你没有相册" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
            [alert show];
        }

    }
    if (buttonIndex == 2){
        NSLog(@"打开相机");
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            // 3.创建并设置打开的类型
            UIImagePickerController * picker = [[UIImagePickerController alloc]init];
            picker.delegate = self;
            picker.allowsEditing = YES;  //是否可编辑
            //摄像头
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:picker animated:YES completion:^{
                
            }];
            
        }else{
            //如果没有提示用户
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"亲，你没有摄像头" delegate:nil cancelButtonTitle:@"Drat!" otherButtonTitles:nil];
            [alert show];
        }

    };
    
}

- (void)saveImage:(UIImage *)image withName:(NSString *)imageName
{
    NSData* imageData = UIImagePNGRepresentation(image);
    　　NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    　　NSString* documentsDirectory = [paths objectAtIndex:0];
    　　// Now we get the full path to the file
    　　NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
    　　// and then we write it out
    　　[imageData writeToFile:fullPathToFile atomically:NO];
}
- (NSString *)documentFolderPath
{
    return [NSHomeDirectory()stringByAppendingPathComponent:@"Documents"];
}
#pragma mark 实现相应的协议方法，打开相机后，然后需要调用UIImagePickerControllerDelegate里的方法，拍摄完成后执行的方法和点击Cancel之后执行的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
        [self dismissViewControllerAnimated:YES completion:^{}];
    // 参数info是一个字典，包含媒体类型，拍照的原始图片，编辑后的图片，或是摄像的视频文件的URL等
    /**
     *  NSString *const  UIImagePickerControllerMediaType ;指定用户选择的媒体类型（文章最后进行扩展）
     NSString *const  UIImagePickerControllerOriginalImage ;原始图片
     NSString *const  UIImagePickerControllerEditedImage ;修改后的图片
     NSString *const  UIImagePickerControllerCropRect ;裁剪尺寸
     NSString *const  UIImagePickerControllerMediaURL ;媒体的URL
     NSString *const  UIImagePickerControllerReferenceURL ;原件的URL
     NSString *const  UIImagePickerControllerMediaMetadata;当来数据来源是照相机的时候这个值才有效
     
     */
    // 得到图片
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    // 将该图片保存到媒体库中, 即相册中
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self saveImage:image withName:@"peopleImg.png"];
    NSString *cutPath = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"peopleImg.png"];
    UIImage *img = [[UIImage alloc]initWithContentsOfFile:cutPath];
    
    [_peopleImg setImage:img];

}



#pragma mark 点击Cancel按钮后执行的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}
#pragma mark 选中图片进入的代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [self dismissModalViewControllerAnimated:YES];
    // 得到图片
    UIImage *imaged = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
    // 将该图片保存到媒体库中, 即相册中
    //    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self saveImage:imaged withName:@"peopleImg.png"];
    NSString *cutPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"peopleImg.png"];
    
    UIImage *img = [[UIImage alloc]initWithContentsOfFile:cutPath];

    [_peopleImg setImage:img];

    
}



#pragma ------抽屉收起手势---------
- (void)tapClick:(UITapGestureRecognizer *)tap
{
    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.chou_Ti_View.frame = CGRectMake(WIDTH, 0, WIDTH / 4 * 3, HEIGHT);
        self.choutibackView.alpha = 0;
//        self.homeTableView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
        
    }];
    
    
}


#pragma ------tableView两个协议方法----------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.homeArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        static NSString *homeReuse = @"homeReuse";
        ZWHomeTableViewCell *homeCell = [tableView dequeueReusableCellWithIdentifier:homeReuse];
        if (!homeCell) {
            homeCell = [[ZWHomeTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:homeReuse];
        }
    

            ZWHomeModel *model = (ZWHomeModel *)self.homeArr[indexPath.row];
    [homeCell.homeImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"占位图01"]];
            homeCell.homeLabel.text = model.scenerie_name;
            homeCell.lineView.layer.cornerRadius = 2;
            homeCell.lineView.layer.borderWidth = 1;
            homeCell.lineView.layer.borderColor = [UIColor whiteColor].CGColor;
            homeCell.hotLabel.text = @"热门景点";
        
        return homeCell;
        

    
}

#pragma ----cell高度-----
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    if (indexPath.row == 0) {
    
//        UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
//        return cell.frame.size.height + 100;
//        return HEIGHT / 7 * 3;
//    }else
//    {
//
//        return WIDTH - 20;
//    }
//    
    return self.homeTableView.rowHeight;
}

#pragma -----table点击方法-----
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    /**
     *  点击时cell颜色消失
     */
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ZWHomeDetail *homeDetail = [[ZWHomeDetail alloc]init];
    
    [self.navigationController pushViewController:homeDetail animated:YES];
//    homeDetail.imgStr = self.homeTableDic[@"image_url"];
    homeDetail.titleStr = ((ZWHomeModel *)self.homeArr[indexPath.row]).scenerie_name;
    homeDetail.uId = ((ZWHomeModel *)self.homeArr[indexPath.row]).equipId;
    
}

#pragma 返回section个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma --sectionView---
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    tableView.sectionHeaderHeight = 10;
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 10)];
    headView.backgroundColor = [UIColor cyanColor];
    return headView;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
